package test.core;
import static test.util.ConstantCollection.*;
import static test.core.HandlingError.*;
import test.core.TCStep;
import test.util.TestConfig;
import test.util.Util;

public class ResultEngine {

	private static TestConfig tc = TestConfig.getInstance();
	public static HandlingError herr = HandlingError.getInstance();
	public static Util u = new Util();
	/**
	 * variable step contains step of testcase 
	 */
	private TCStep step;
	
	/**
	 * variable lastStepId is numerator of testcase's steps
	 */
	private Integer lastStep = 0;
	
	public TCStep getStep() {
    	return step;
    }
	
    /**
     * Add new step of test case, and passes it to addToConsole method.
     * @param id Identifire
     * @param name of actions, title of message
     */
    public void newStep(String id, String name) {
    	TCStep step = new TCStep(id, name);
    	
    	addToConsole("STEP:" + id + ". (" + u.getTime(step.getTime()) + ")" + step.getName());
    	this.step = step;
    	lastStep = lastStep + 1;
    	//lastStepTime = step.getTime();
    }
    
    /**
     * Create new step (with Id) of test case, and passes it to addToConsole method.
     * @param name of actions, title of message
     */
    public void newStep(String name) {
    	Integer id = lastStep + 1;
    	TCStep step = new TCStep(id.toString(), name);
    	
    	addToConsole("STEP:" + step.getId() + ". (" + u.getTime(step.getTime()) + ")" + step.getName());
    	this.step = step;
    	lastStep = id;
    }
    
    /**
     * Send to console input information .
     * @param text Text that display in console
     */
    private void addToConsole(String text) {
    	addToConsole(0, text);
    }
    
    /**
     * Send to console input information .
     * @param status
     * @param description 
     */
    public void addToConsole(Integer status, String description) {
    	switch(status) {
		case STATUS_ERROR: 
			System.err.println(description);
			org.testng.Reporter.log(description);
			break;
		default:
			if (tc.getEnv("addpasssteptoresult").toLowerCase().contentEquals("true")) {
	    		System.out.println(description);
	    		org.testng.Reporter.log(description);
	    	}
			break;
		}
    }
}
